<?php
	class EventController extends BaseController {
		public function eventFeed()
		{
			$raids = Raid::get();

			$jsonRaid = array();

			if(Auth::check())
			{
				$mychar = Characters::where("user_id", "=", Auth::user()->id)->get();
			}

			foreach($raids as $raid)
			{
				$isMember = false;

				if(Auth::check())
				{
					$membersArray = array();

					$members = RaidMember::where("raid_id", "=", $raid->raid_id)->get(array('name'));

					foreach($members as $member)
					{
						$membersArray[] = $member->name;
					}

					foreach($mychar as $char)
					{
						if(in_array($char->char_name, $membersArray))
						{
							$isMember =  true;
							break;
						}
					}
				}
				$jsonRaidRow = array();
				$jsonRaidRow['id'] = $raid->raid_id;
				$jsonRaidRow['title'] = $raid->instance;
				$datetime = new DateTime($raid->date);
				$jsonRaidRow['start'] = $datetime->format(DateTime::ISO8601);
				if($isMember)
				{
					$jsonRaidRow['color'] = 'red';
				}
				$jsonRaid[] = $jsonRaidRow;
			}

			return json_encode($jsonRaid);
		}

		public function eventMember($id)
		{
			$members = RaidMember::where("raid_id", "=", $id)->get();

			$membersArray = array();

			foreach($members as $member)
			{
				$membersArray[] = $member->name;
			}

			return implode("<br/>", $membersArray);
		}
	}